{% extends "layout.html" %}
{% block body %}
<style type="text/css">
    .problem-header{
    text-align: center;
    }
    .am-panel-title{
    font-size: 1.3em;
    }
</style>
<div class="am-container am-g">
    <div class="am-u-sm-12 problem-header">
        <h1>{{problem.title}}{% if not problem.is_public %}--[未审核]{% endif %}</h1>

        <p>
            <span class="am-badge am-badge-success am-text-sm">内存限制: {{problem.memory_limit}} MB</span>
            <span class="am-badge am-badge-warning am-text-sm">时间限制: {{problem.time_limit}} ms</span>
        </p>
    </div>
    <div class="am-u-sm-12">
        <a class="am-btn am-btn-primary am-btn-sm am-fl" href="{{url_for('submit_code',problem_id=problem.id)}}">提交此题</a>
        <a class="am-btn am-btn-danger am-btn-sm am-fl" href="{{url_for('judge_state')}}?{{tool.url_encode({'problem_id':problem.id})}}">此题提交情况</a>
        {% if problem.is_allowed_edit(user) %}
        <a class="am-btn am-btn-success am-btn-sm am-fl" href="{{url_for('edit_problem',problem_id=problem.id)}}">编辑题面</a>
        <a class="am-btn am-btn-secondary am-btn-sm am-fl" href="{{url_for('upload_testdata',problem_id=problem.id)}}">上传测试数据</a>
        {% endif %}

        {% if user and user.have_privilege(2) %}
            {% if problem.is_public %}
            <button class="am-btn am-btn-default am-btn-sm am-fr" id="dis_public">取消审核</button>
            {%else%}
            <button class="am-btn am-btn-default am-btn-sm am-fr" id="public">通过审核</button>
            {%endif %}
        {% endif %}
    </div>
    <div class="am-u-sm-12">
        <div class="am-panel am-panel-default" id="problem-panel">
    
            <div class="am-panel-hd"><h3 class="am-panel-title">题目描述</h3></div>
            <div class="am-panel-bd" id="description">{{problem.description}}</div>
    
            <div class="am-panel-hd"><h3 class="am-panel-title">输入格式</h3></div>
            <div class="am-panel-bd" id="input">{{problem.input_format}}</div>
    
            <div class="am-panel-hd"><h3 class="am-panel-title">输出格式</h3></div>
            <div class="am-panel-bd" id="output">{{problem.output_format}}</div>
    
            <div class="am-panel-hd"><h3 class="am-panel-title">测试样例</h3></div>
            <div class="am-panel-bd" id="example">{{problem.example}}</div>
    
            <div class="am-panel-hd"><h3 class="am-panel-title">数据范围与提示</h3></div>
            <div class="am-panel-bd" id="hint">{{problem.limit_and_hint}}</div>
        </div>
    </div>
</div>
{% endblock %}
{% block script %}

<!-- KaTex -->
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/KaTeX/0.6.0/katex.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/KaTeX/0.6.0/katex.min.js"></script>
<!-- KaTex autoRender -->
<script src="{{ url_for('static', filename='auto-render.js') }}"></script>

<script src="{{ url_for('static', filename='marked.js') }}"></script>
<script type="text/javascript">
function render(tag){
    tag.html(marked(tag.html()));
}
marked.setOptions({
  highlight: function (code) {
    return "<code>"+code+"</code>";
  }
});
$(document).ready(function(){
    render($("#description"));
    render($("#input"));
    render($("#output"));
    render($("#example"));
    render($("#hint"));
    renderMathInElement(document.getElementById("problem-panel"));
    $("pre").addClass("prettyprint");
    prettyPrint();
});
function public_problem(){
    url='/api/problem/{{problem.id}}/public?session_id='+$.cookie("session_id");
    url=encodeURI(url);
    $.ajax({
        url : url,
        type : 'POST',
        async:false,
    });
}
function dis_public_problem(){
    url='/api/problem/{{problem.id}}/public?session_id='+$.cookie("session_id");
    url=encodeURI(url);
    $.ajax({
        url : url,
        type : 'DELETE',
        async:false,
    });
}
$(document).ready(function(){
    $("#public").click(function(){
        public_problem();
        location.reload(true);
    });
    $("#dis_public").click(function(){
        dis_public_problem();
        location.reload(true);
    });
});

</script>
{% endblock %}
